from tkinter import *
from datetime import datetime
import MySQLdb

root=Tk()
root.title('MySQL口令刷新器')
root.geometry("520x250+200+200")   # 窗体大小和靠左靠右间距

formatted_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

#重置
def ReSet():
    username=En.get()
    password = En1.get()

    print(username)
    print(password)

    conn = MySQLdb.connect(
        host="10.120.86.42",  # 数据库主机地址
        port=33061,
        user="6e6a02eb-e7f5-474e-b07b-27411a9ca40e",  # 用户名
        passwd="BEkKLG8b1VZaENph",  # 密码
        db="device"  # 数据库名称
    )

    try:
        # 创建游标对象
        cursor = conn.cursor()

        # 执行SQL查询
        cursor.execute("SELECT VERSION();")

        # 获取单条结果
        data = cursor.fetchone()
        print(f"Database version: {data[0]}")

        # cursor.execute("select t.benchmark_no from eac_benchmark_data t")
        #
        # # 获取查询结果
        # results = cursor.fetchall()
        # for row in results:
        #     print(row)

    finally:
        # 关闭游标和连接
        cursor.close()
        conn.close()
    listbox.insert(END, formatted_time)

label=Label(root,text='用户:',anchor='c',width=10).grid(row=0)
En=Entry(root,width=58)
En.grid(row=0,column=1)

label1=Label(root,text='密码:',anchor='c',width=10).grid(row=1)
En1=Entry(root,width=58)
En1.grid(row=1,column=1)

Button(root,text='启动',anchor='c',width=6,height=1,command=ReSet).grid(row=2,column=1)
listbox=Listbox(root,width=58,height=8)
listbox.grid(row=3,column=1)

root.mainloop()